package com.tongji.diy.view.component3D
{
	import com.tongji.diy.model.RoomControlPoint;
	import com.tongji.diy.model.RoomDataVO;
	import com.tongji.diy.utils.RoomParameters;
	import com.tongji.diy.view.material.DefaultMaterial;
	
	import de.polygonal.ds.DListNode;
	
	import flare.basic.Scene3D;
	import flare.core.Pivot3D;
	import flare.core.Texture3D;
	import flare.materials.Shader3D;
	import flare.materials.filters.ColorFilter;
	import flare.materials.filters.TextureFilter;
	import flare.primitives.Sphere;
	
	import flash.display.BitmapData;
	import flash.display.GradientType;
	import flash.display.Shape;
	import flash.events.Event;
	import flash.filters.GlowFilter;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	/**
	 * 
	 * @author xxj
	 * 
	 */
	
	public class Room extends Pivot3D
	{
		private var vertexMaterial:Shader3D
		private var wallPaper:Texture3D
		public var roomFloor:RoomFloor;
		public var roomIndex:uint;
		private var roomData:RoomDataVO;
		
		public function Room(roomData:RoomDataVO, name:String="")
		{
			super(name);
			
			this.roomIndex = roomData.roomIndex;
			this.roomData = roomData;
			this.name = roomIndex.toString();
			this.vertexMaterial = DefaultMaterial.getInst() as Shader3D;
			
			initVertex(this.roomData);
			initWall(this.roomData);
			initFloor(this.roomData);
		}
		
		private function initVertex(roomData:RoomDataVO):void
		{
			var currentNode:DListNode = roomData.roomPointList.head;
			var roomVertex:RoomVertex = new RoomVertex(currentNode,vertexMaterial);
			this.addChild(roomVertex)
			while (currentNode.next != roomData.roomPointList.head)
			{
				currentNode = currentNode.next;
				roomVertex = new RoomVertex(currentNode,vertexMaterial);
				this.addChild(roomVertex)
			}
		}
		
		private function initWall(roomData:RoomDataVO):void
		{
			var startNode:DListNode = roomData.roomPointList.head;
			var endNode:DListNode = startNode.next;
			var roomBorder:RoomBorder = new RoomBorder(startNode,endNode,vertexMaterial);
			this.addChild(roomBorder);
			while (startNode.next != roomData.roomPointList.head)
			{
				startNode = startNode.next;
				endNode = endNode.next;
				roomBorder = new RoomBorder(startNode,endNode,vertexMaterial);
				this.addChild(roomBorder);
			}
		}
		
		private function initFloor(roomData:RoomDataVO):void
		{
			roomFloor = new RoomFloor(roomData,vertexMaterial);
			this.addChild(roomFloor);
		}
		
	}
}